﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace t01crm.Data
{ 
    // [ContentPropertyAttribute("Description")]
    public class Listing : BusinessEntity 
    {
        static Random R = new Random();
        public Listing()
        {
            this.ClientRating = R.Next(0, 6);
        }

       // internal ListingCollection ParentListingCollection;

        public string MLS { get; set; }
        public string Title { get; set; }
        public double Price { get; set; }

        public Address Address
        {
            get;
            set;
        } 
          
        public int? NeighborhoodId { get; set; }
        public string Description { get; set; }
        public double BedroomCount { get; set; }
        public double BathroomCount { get; set; }
        public int Year { get; set; }
        public double SquareFootage { get; set; }
        public List<string> Photos { get; set; }
        public int ClientRating { get; set; }

        private string _primaryPhoto = null;
        public string PrimaryPhoto
        {
            get { return _primaryPhoto; }
            set
            {
                _primaryPhoto = value;
                OnPropertyChanged("PrimaryPhoto");
                OnPropertyChanged("HasPhotos");
            }
        }

        public bool HasPhotos
        {
            get { return !String.IsNullOrEmpty(PrimaryPhoto); }
        }

        Neighborhood _cachedNeighborhood; 

        public Neighborhood Neighborhood
        {
            get
            {
                if ( _cachedNeighborhood  == null   
                 /* this.ParentListingCollection != null */ && this.NeighborhoodId != null)
                {
                    /*this.ParentListingCollection.GetNeighborhoodById(this.NeighborhoodId.Value); */ 
                        _cachedNeighborhood = Neighborhood.Find ( this.NeighborhoodId.Value ); 
                }
                return _cachedNeighborhood ;
            }
        }
    }

    public class Neighborhood : DataEntity 
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool IsHighGrowth { get; set; }
        public bool IsNearCityCenter { get; set; }
        public bool IsNearDining { get; set; }
        public bool IsNearShopping { get; set; }
        public bool IsNearCommunityCenter { get; set; }
        public bool IsNearParks { get; set; }
        public bool IsNearFamilyActivities { get; set; }
        public List<string> Photos { get; set; }

        public bool HasPhotos
        {
            get { return (Photos.Count != 0); }
        }

        public override string ToString()
        {
            return this.Name;
        }

        public static Neighborhood Find(int id)
        {
            //TODO : implement 
            return new Neighborhood(); 
        } 
    }
}
